package com.fan.springboot1903fanjianghao.config;

import com.fan.springboot1903fanjianghao.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ZixiaFan
 * 2021/11/15 23:38
 *
 * 1、编写一个拦截器，实现HandlerInterceptor
 * 2、拦截器注册到容器中（实现WebMvcConfigurer的addInterceptors方法）
 * 3、指定拦截规则{放开静态资源}
 *
 * @EnableWebMvc:全面接管springMVC     慎用！！！   使用之后所有的MVC自定配置全部失效
 */
//@EnableWebMvc
@Configuration
public class AdminWebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")  //所有请求都会被拦截，包括静态资源
                .excludePathPatterns("/register.html","/register","/toLogin","login.html","/UniqueUsername.do","/register.do","/","/login.do","/assets/**","/bootstrap-3.4.1-dist/**","/css/**","/images/**","/js/**");
    }
}
